﻿<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="更新时间" prop="UpdateTime">
          <a-input v-model="entity.UpdateTime" autocomplete="off" placeholder="更新时间" />
        </a-form-model-item>
        <a-form-model-item label="自定义编码" prop="Code">
          <a-input v-model="entity.Code" autocomplete="off" placeholder="自定义编码" />
        </a-form-model-item>
        <a-form-model-item label="排序" prop="Sort">
          <a-input v-model="entity.Sort" autocomplete="off" placeholder="越小越靠前" />
        </a-form-model-item>
        <a-form-model-item label="备注" prop="Remark">
          <a-input v-model="entity.Remark" autocomplete="off" placeholder="备注" />
        </a-form-model-item>
        <a-form-model-item label="楼栋ID" prop="BuildingId">
          <a-input v-model="entity.BuildingId" autocomplete="off" placeholder="楼栋ID" />
        </a-form-model-item>
        <a-form-model-item label="地上层还是地下层" prop="IsOnGround">
          <a-input v-model="entity.IsOnGround" autocomplete="off" placeholder="1-地上，2-地下" />
        </a-form-model-item>
        <a-form-model-item label="所在楼层号" prop="Storey">
          <a-input v-model="entity.Storey" autocomplete="off" placeholder="Storey" />
        </a-form-model-item>
        <a-form-model-item label="工程编号" prop="ProjectCode">
          <a-input v-model="entity.ProjectCode" autocomplete="off" placeholder="工程编号" />
        </a-form-model-item>
        <a-form-model-item label="招商编码" prop="InvestmentCode">
          <a-input v-model="entity.InvestmentCode" autocomplete="off" placeholder="招商编码" />
        </a-form-model-item>
        <a-form-model-item label="商铺编号" prop="ShopCode">
          <a-input v-model="entity.ShopCode" autocomplete="off" placeholder="商铺编号" />
        </a-form-model-item>
        <a-form-model-item label="商铺名称" prop="ShopName">
          <a-input v-model="entity.ShopName" autocomplete="off" placeholder="商铺名称" />
        </a-form-model-item>
        <a-form-model-item label="原商铺ID信息" prop="ShopLastIds">
          <a-input v-model="entity.ShopLastIds" autocomplete="off" placeholder="原商铺ID信息" />
        </a-form-model-item>
        <a-form-model-item label="商铺面积" prop="ShopArea">
          <a-input v-model="entity.ShopArea" autocomplete="off" placeholder="商铺面积" />
        </a-form-model-item>
        <a-form-model-item label="业态级别" prop="ShopFormatClass">
          <a-input v-model="entity.ShopFormatClass" autocomplete="off" placeholder="业态级别" />
        </a-form-model-item>
        <a-form-model-item label="业态名称" prop="ShopFormatName">
          <a-input v-model="entity.ShopFormatName" autocomplete="off" placeholder="业态名称" />
        </a-form-model-item>
        <a-form-model-item label="商铺品牌信息" prop="ShopBrand">
          <a-input v-model="entity.ShopBrand" autocomplete="off" placeholder="商铺品牌信息" />
        </a-form-model-item>
        <a-form-model-item label="商铺分隔模式" prop="ShopSeparation">
          <a-input v-model="entity.ShopSeparation" autocomplete="off" placeholder="商铺分隔模式" />
        </a-form-model-item>
        <a-form-model-item label="商铺变更原因" prop="ShopChangeReason">
          <a-input v-model="entity.ShopChangeReason" autocomplete="off" placeholder="商铺变更原因" />
        </a-form-model-item>
        <a-form-model-item label="版本号" prop="ChangeVersion">
          <a-input v-model="entity.ChangeVersion" autocomplete="off" placeholder="版本号" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    init () {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm (id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/Shop_Manage/Shop_BaseInfo/GetTheData', { id: id }).then(resJson => {
          this.loading = false
          this.entity = resJson.Data
        })
      }
    },
    handleSubmit () {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/Shop_Manage/Shop_BaseInfo/SaveData', this.entity).then(resJson => {
          this.loading = false
          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.loading = false
            this.visible = false
	    this.$emit('returnMain')
            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
            this.loading = false
          }
        })
      })
    },
    // 非空校验
    validEmpty (index, name, tips) {
      return (rule, value, callback) => {
        const data = this.DetaiData[index][name]
        if (!data) {
          this.$message.warning('列表第' + (index + 1) + '行：' + tips)
          callback(tips || '必填')
        } else {
          callback()
        }
      }
    }
  }
}
</script>
<style scoped>
</style>
